// pages/category/category.js
Page({

  data: {
    categoriesList:[],// 数据
    categoriestitle:[], // 标题
    categoriesIndex:0
  },

  onLoad: function (options) {
    this.List = []  // 定义一个全局变量

    // 发送请求
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/categories',
      success:(res)=>{
        this.List =  res.data.message
        const categoriestitle = this.List.map(item=> item.cat_name)
        const categoriesList = this.List[0].children
        this.setData({categoriestitle,categoriesList})
      }
    })
  },

  // 点击事件
  headerTap(e){
    const categoriesIndex = e.target.dataset.index
    const categoriesList = this.List[categoriesIndex].children
    this.setData({categoriesList,categoriesIndex})
  }
})